home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / ReadLuminanceRecord.c < prev    next >
Text File  |  1995-11-09  |  7KB  |  188 lines

  1. /*
  2. ReadLuminanceRecord.c
  3.  
  4. long InitializeLuminanceRecord(LuminanceRecord *LP,short flags);
  5.  
  6.     i=ReadLuminanceRecord("LuminanceRecord1.h",&LR,0);
  7. Reads a LuminanceRecord?.h file at runtime. In the past, these calibration-data files
  8. could only be used by #including them at compile time.
  9.  
  10.     long WriteLuminanceRecord(char *filename,LuminanceRecord *LP,short flags);
  11. Writes (and verifies) a LuminanceRecord, appending to the file.
  12.  
  13.     Description *DescribeLuminanceRecord(LuminanceRecord *LP);
  14. Creates a Description array to read and write LuminanceRecord assignment files.
  15.  
  16.  
  17. HISTORY:
  18. 7/29/91 dgp
  19. 8/24/91    dgp    Made compatible with THINK C 5.0.
  20.             Preserve default values of LP->VMin and LP->VMax if no new values are read.
  21. 8/26/91    dgp    Rewrote using new SetVariable() routine, which makes the code easier to
  22.             read. 
  23. 12/17/92 dgp Added dacSize.
  24. 12/21/92 dgp Changed type of dacSize from long to short.
  25. 6/3/93    dgp    Updated to work with new Assign.c. 
  26.             Created DescribeLuminanceRecordAssignment() and WriteLuminanceRecord().
  27. 8/12/93    dgp    Renamed routines to be consistent with new Assign.c.
  28.             Renamed "DescribeLuminanceRecordAssignment" to "DescribeLuminanceRecord".
  29. 3/4/94    dgp ReadLuminanceRecord no longer initializes. Added InitializeLuminanceRecord.
  30. 8/15/95 dgp fixed typo in error message string reported by Bosco.
  31. 11/9/95 dgp changed file creator of LuminanceRecord file to 'CWIE', i.e. CodeWarrior text file.
  32. */
  33.  
  34. #include "VideoToolbox.h"
  35. #include "Luminance.h"
  36. #define VARIABLES 32
  37. long InitializeLuminanceRecord(LuminanceRecord *LP,short flags);
  38.  
  39. long InitializeLuminanceRecord(LuminanceRecord *LP,short flags)
  40. {
  41.     Description *d;
  42.     long n;
  43.  
  44.     d=DescribeLuminanceRecord(LP);
  45.     if(d==NULL){
  46.         if(flags&assignNoPrintfExit)return assignMemoryError;
  47.         else PrintfExit("\nInitializeLuminanceRecord: no room for Variables.\n\007");
  48.     }
  49.     n=InitializeDescribedVars(d,flags);
  50.     LP->dacSize=8;                    /*  default value */
  51.     free(d);
  52.     return n;
  53. }
  54.  
  55. long ReadLuminanceRecord(char *filename,LuminanceRecord *LP,short flags)
  56. {
  57.     Description *d;
  58.     long n;
  59.  
  60.     assert(LP!=NULL);
  61.     d=DescribeLuminanceRecord(LP);
  62.     if(d==NULL){
  63.         if(flags&assignNoPrintfExit)return assignMemoryError;
  64.         else PrintfExit("\nReadLuminanceRecord: no room for Variables.\n\007");
  65.     }
  66. //    n=InitializeDescribedVars(d,flags);
  67.     LP->dacSize=8;                    /*  default value */
  68.     n=ReadAssignmentFile(filename,d,flags);
  69.     free(d);
  70.     return n;
  71. }
  72.  
  73. long WriteLuminanceRecord(char *filename,LuminanceRecord *LP,short flags)
  74. {
  75.     Description *d=NULL,*d2=NULL;
  76.     LuminanceRecord *LP2=NULL;
  77.     long n,m;
  78.  
  79.     /*  Write */
  80.     assert(LP!=NULL);
  81.     d=DescribeLuminanceRecord(LP);
  82.     if(d==NULL){
  83.         n=assignMemoryError;
  84.         if(flags&assignNoPrintfExit)goto done;
  85.         else PrintfExit("\nWriteLuminanceRecord: no room for Variables.\n\007");
  86.     }
  87.     n=PrintAssignmentsToFile(filename,d,flags);
  88.     SetFileInfo(filename,'TEXT','CWIE');
  89.     if(n<0)goto done;
  90.     
  91.     /*  Verify */
  92.     LP2=(LuminanceRecord *)malloc(sizeof(LuminanceRecord));
  93.     if(LP2==NULL){
  94.         n=assignMemoryError;
  95.         if(flags&assignNoPrintfExit)goto done;
  96.         else PrintfExit("\nWriteLuminanceRecord: no room for LuminanceRecord.\n\007");
  97.     }
  98.     d2=DescribeLuminanceRecord(LP2);
  99.     if(d2==NULL){
  100.         n=assignMemoryError;
  101.         if(flags&assignNoPrintfExit)goto done;
  102.         else PrintfExit("\nWriteLuminanceRecord: no room for Variables.\n\007");
  103.     }
  104.     m=ReadAssignmentFile(filename,d2,flags|assignReportUnknown);
  105.     if(m<0){
  106.         n=m;
  107.         goto done;
  108.     }
  109.     m=UnequalDescribedVars(d,d2,flags);
  110.     if(m<0){
  111.         n=m;
  112.         goto done;
  113.     }
  114. done:
  115.     if(d2!=NULL)free(d2);
  116.     if(LP2!=NULL)free(LP2);
  117.     if(d!=NULL)free(d);
  118.     return n;
  119. }
  120.  
  121. Description *DescribeLuminanceRecord(LuminanceRecord *LP)
  122. {
  123.     Description *d;
  124.     int j;
  125.  
  126.     d=(Description *)malloc(VARIABLES*sizeof(Description));
  127.     if(d==NULL)return NULL;
  128.     j=0;
  129.     d[j++]=Describe(shortType,&LP->screen,"LR.screen"
  130.         ,"device=GetScreenDevice(LR.screen);");
  131.     d[j++]=Describe(stringType,&LP->id,"LR.id",NULL);
  132.     d[j++]=Describe(stringType,&LP->name,"LR.name",NULL);
  133.     d[j++]=Describe(stringType,&LP->date,"LR.date",NULL);
  134.     d[j++]=Describe(stringType,&LP->notes,"LR.notes",NULL);
  135.     d[j++]=Describe(shortType,&LP->dacSize,"LR.dacSize",NULL);
  136.     d[j++]=Describe(doubleType,&LP->LMin,"LR.LMin","luminance at VMin");
  137.     d[j++]=Describe(doubleType,&LP->LMax,"LR.LMax"
  138.         ,"luminance at VMax");
  139.     d[j++]=Describe(doubleType,&LP->LBackground,"LR.LBackground"
  140.         ,"background luminance during calibration");
  141.     d[j++]=Describe(shortType,&LP->VBackground,"LR.VBackground"
  142.         ,"background number used during calibration");
  143.     d[j++]=Describe(doubleType,&LP->dpi,"LR.dpi","pixels/inch");
  144.     d[j++]=Describe(doubleType,&LP->Hz,"LR.Hz","frames/second");
  145.     d[j++]=Describe(stringType,&LP->units,"LR.units",NULL);
  146.     d[j++]=Describe(longType,&LP->coefficients,"LR.coefficients"
  147.         ,"# of coefficients in polynomial fit");
  148.     d[j++]=DescribeArray(doubleType,&LP->p,"LR.p"
  149.         ,"L(V)=p[0]+p[1]*V+p[2]*V*V+ . . . ±polynomialError"
  150.         ,sizeof(LP->p)/sizeof(LP->p[0]),0L);
  151.     d[j++]=Describe(doubleType,&LP->polynomialError,"LR.polynomialError"
  152.         ,"RMS error of fit");
  153.     d[j++]=DescribeArray(doubleType,&LP->q,"LR.q"
  154.         ,"L(V)=q[0]+q[1]*V+q[2]*V*V±quadraticError",sizeof(LP->q)/sizeof(LP->q[0]),0L);
  155.     d[j++]=Describe(doubleType,&LP->quadraticError,"LR.quadraticError"
  156.         ,"RMS error of fit");
  157.     d[j++]=DescribeArray(doubleType,&LP->power,"LR.power"
  158.         ,"L(V)=power[0]+Rectify(power[1]+power[2]*V)^power[3]±powerError */\\\n"
  159.         "    /* where Rectify(x)=x if x≥0, and Rectify(x)=0 otherwise. */\\\n"
  160.         "    /* Pelli & Zhang (1991) Eqs.9&10 use symbols v=V/255, */\\\n"
  161.         "    /* alpha=power[0], beta=power[1], kappa=power[2]*255, gamma=power[3]"
  162.         ,sizeof(LP->power)/sizeof(LP->power[0]),0L);
  163.     d[j++]=Describe(doubleType,&LP->powerError,"LR.powerError"
  164.         ,"RMS error of fit");
  165.     d[j++]=DescribeArray(doubleType,&LP->fixedPower,"LR.fixedPower"
  166.         ,"L(V)=fixedPower[0]+Rectify(fixedPower[1]+fixedPower[2]*V)^fixedPower[3]±fixedPowerError */\\\n"
  167.         "    /* The exponent fixedPower[3] is fixed."
  168.         ,sizeof(LP->fixedPower)/sizeof(LP->fixedPower[0]),0L);
  169.     d[j++]=Describe(doubleType,&LP->fixedPowerError,"LR.fixedPowerError"
  170.         ,"RMS error of fit");
  171.     d[j++]=Describe(doubleType,&LP->r,"LR.r",NULL);
  172.     d[j++]=Describe(doubleType,&LP->g,"LR.g",NULL);
  173.     d[j++]=Describe(doubleType,&LP->b,"LR.b",NULL);
  174.     d[j++]=Describe(doubleType,&LP->gainAccuracy,"LR.gainAccuracy",NULL);
  175.     d[j++]=Describe(doubleType,&LP->gm,"LR.gm"
  176.         ,"The monitor's contrast gain.");
  177.     d[j++]=Describe(shortType,&LP->rangeSet,"LR.rangeSet"
  178.         ,"zero indicates that range parameters have yet to be set");
  179.     d[j++]=Describe(shortType,&LP->L.exists,"LR.L.exists"
  180.         ,"zero indicates that luminance table has yet to be initialized");
  181.     d[j++]=Describe(shortType,&LP->VMin,"LR.VMin"
  182.         ,"minimum value that can be loaded into DAC");
  183.     d[j++]=Describe(shortType,&LP->VMax,"LR.VMax"
  184.         ,"maximum value that can be loaded into DAC");
  185.     d[j++]=Describe(0,NULL,NULL,NULL);                /* Mark end of list */
  186.     assert(j<=VARIABLES);
  187.     return d;
  188. }